package com.aliyun.demo.wenxin.service.impl;

import com.aliyun.demo.wenxin.dao.UserDao;
import com.aliyun.demo.wenxin.entity.TUser;
import com.aliyun.demo.wenxin.dao.TUserDao;
import com.aliyun.demo.wenxin.service.TUserService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TUser)表服务实现类
 * @author version
 * @since 2020-07-31 21:25:34
 */
@Service("TUserService")
public class TUserServiceImpl implements TUserService {
    @Resource
    private TUserDao tUserDao;
    @Autowired
    private UserDao userDao;
    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TUser queryById(Integer id) {

        return userDao.selectById(id);
    }

    @Override
    public List<TUser> queryAllByLimit(int offset, int limit) {
        return null;
    }

    /**
     * 查询多条数据
     * @return 对象列表
     */
    @Override
    public List<TUser> queryAllByLimit() {

        return userDao.selectList(null);
    }

    /**
     * 新增数据
     *
     * @param tUser 实例对象
     * @return 实例对象
     */
    @Override
    public TUser insert(TUser tUser) {
        this.tUserDao.insert(tUser);
        return tUser;
    }

    /**
     * 修改数据
     *
     * @param tUser 实例对象
     * @return 实例对象
     */
    @Override
    public TUser update(TUser tUser) {
        this.tUserDao.update(tUser);
        return this.queryById(tUser.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.tUserDao.deleteById(id) > 0;
    }
}